<template>
  <div>
    <div>
      <a-card :bordered="false">
        <!-- 研究者费用 -->
        <ResearcherList
          :proId="proId"
          :approval="researchApprovalInfo"
          :all-center-list="allCenterList"
          v-if="$auth('PROJECT.PROJECT_FEE') && $auth('PROJECT.PROJECT_FEE_RESEARCHER')"
        />
        <!-- 受试者者费用 -->
        <SubjectList
          :proId="proId"
          style="margin-top: 24px"
          :approval="subjectApprovalInfo"
          :all-center-list="allCenterList"
          v-if="$auth('PROJECT.PROJECT_FEE') && $auth('PROJECT.PROJECT_FEE_PATIENT')"
        />
      </a-card>
    </div>
  </div>
</template>

<script>
import { getApprovalDetail } from '@/api/overview/approval'
import ResearcherList from './researcher/ResearcherList'
import SubjectList from './subject/SubjectList'
import { apiGetAllCenter } from '@api/cost/cost'

export default {
  components: {
    ResearcherList,
    SubjectList
  },
  data () {
    return {
      proId: '',
      researchApprovalInfo: {}, // 研究者审批流
      subjectApprovalInfo: {}, // 受试者审批流
      allCenterList: [] // 所有中心列表
    }
  },
  created () {
    this.getProjectId()
  },
  mounted () {
    this.initApproval()
    this.getAllCenterList()
  },
  methods: {
    // 获取项目id
    getProjectId () {
      const pro = localStorage.getItem('CURRENT_PROID')
      if (pro) {
        this.proId = parseInt(pro)
      }
    },
    // 获取审批流详情
    async initApproval () {
      const proId = this.proId
      if (!this.$auth('PROJECT.PROJECT_FEE_PATIENT_COMMIT')) return
      if (this.$auth('PROJECT.PROJECT_FEE') && this.$auth('PROJECT.PROJECT_FEE_RESEARCHER')) {
        this.researchApprovalInfo = await getApprovalDetail({
          proId,
          type: 1
        })
      }
      if (this.$auth('PROJECT.PROJECT_FEE') && this.$auth('PROJECT.PROJECT_FEE_PATIENT')) {
        this.subjectApprovalInfo = await getApprovalDetail({
          proId,
          type: 2
        })
      }
    },
    // 获取所有中心下拉列表
    getAllCenterList () {
      apiGetAllCenter({ proId: this.proId }).then(res => {
        this.allCenterList = res
      })
    }
  }
}
</script>
